package com.wnxy.set;

import java.util.HashSet;
import java.util.Objects;

class TestVo{
    int id;
    private String name;
    public TestVo(int id,String name){
        this.id = id;
        this.name = name;
    }

    @Override
    public String toString() {
        return "TestVo{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        TestVo testVo = (TestVo) o;
        return id == testVo.id && Objects.equals(name, testVo.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name);
    }
}
public class App2 {
    public static void main(String[] args) {
        // 无序不重复
        HashSet<TestVo> set = new HashSet();

        TestVo jack = new TestVo(100,"jack");
        TestVo rose = new TestVo(100,"jack");

        set.add(jack);
        set.add(rose);

        System.out.println("set = " + set);
    }
}
